package com.gukun.springboot.tdengine.service.delete;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gukun.springboot.tdengine.dao.DeleteLogMapper;
import com.gukun.springboot.tdengine.domain.delete.DeleteLog;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 4998
 * @createDate: 2025-06-04  09:42
 * @description:
 */
@Service
public class DeleteLogService {
    @Autowired
    private DeleteLogMapper deleteLogMapper;
    public List<DeleteLog> listDeleteLog(String taskId) {
        LambdaQueryWrapper<DeleteLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DeleteLog::getTaskId, taskId);
        queryWrapper.orderByDesc(DeleteLog::getStartTime);
        return deleteLogMapper.selectList(queryWrapper);
    }

    public void saveOrUpdate(DeleteLog deleteLog){
        String id = deleteLog.getId();
        if(StringUtils.isNotBlank(id)){
            deleteLogMapper.updateById(deleteLog);
        }else{
            deleteLogMapper.insert(deleteLog);
        }
    }

    public void deleteByTaskId(String taskId){
        LambdaQueryWrapper<DeleteLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DeleteLog::getTaskId, taskId);
        deleteLogMapper.delete(queryWrapper);
    }

    public DeleteLog getById(String logId) {
        return deleteLogMapper.selectById(logId);
    }
}
